import React, { useState, useEffect }  from "react"

import store from "../../redux/store"
import {pAction, mAction} from "../../redux/reducer"

export default function Count() {
  const [count, setCount] = useState()

  const plus=()=>{
    store.dispatch(pAction({value:1}))
  }
  const minus=()=>{
    store.dispatch(mAction({value:1}))
  }

  useEffect(()=>{
    store.subscribe(()=>{
      const state = store.getState()
      setCount(state.counter.count)
    })
  })

  return (
    <div>
      <p>结果:{count}</p>
      <button onClick={plus}>+</button>
      <button onClick={minus}>-</button>
    </div>
  )
}
